<?php

//路由分发
class Dispatcher {

    protected $default_controller = 'Index';
    protected $default_action = 'index';

    public function dispatch() {
        if(isset($_SERVER['PATH_INFO'])){
            $params = explode('/', ltrim($_SERVER['PATH_INFO'],'/'));
        }
        $controller = isset($params[0]) ? ucfirst(strtolower($params[0])) : $this->default_controller;
        $action = isset($params[1]) ? strtolower($params[1]) : $this->default_action;
        $controller_name = $controller . 'Controller';
        $obj = new $controller_name;
        $obj->$action();
    }

}
